package com.geektime.congestion.wallet.dao;

import com.geektime.congestion.wallet.domain.WalletTransaction;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class WalletTransactionDao {

    private static List<WalletTransaction> walletTransactionList = new ArrayList<>();

    public WalletTransaction save(WalletTransaction transaction) {
        List<WalletTransaction> list = walletTransactionList.stream()
                .filter(item -> item.getUuid().equals(transaction.getUuid())).collect(Collectors.toList());
        if (list.isEmpty()) {
            walletTransactionList.add(transaction);
        } else {
            walletTransactionList.remove(list.get(0));
            walletTransactionList.add(transaction);
        }
        return transaction;
    }

}
